<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>、
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
          integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css"
          integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
    <link rel="stylesheet" href="css/login.css">
    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"
            integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
            crossorigin="anonymous"></script>
</head>
<body>
<div class="nav-wrapper">
    <nav class="navbar navbar-default navbar-inverse navbar-fixed-top">
        <div class="container-fluid">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                        data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">XX购物平台</a>
            </div>
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li><a href="goodsList.html">首页<span class="sr-only">(current)</span></a></li>
                    <li class="active"><a href="login.html">登陆</a></li>
                    <li><a href="register.html">注册</a></li>
                    <li><a href="#">收藏</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                           aria-expanded="false">Dropdown <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Action</a></li>
                            <li><a href="#">Another action</a></li>
                            <li><a href="#">Something else here</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="#">Separated link</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="#">One more separated link</a></li>
                        </ul>
                    </li>
                </ul>
                <form class="navbar-form navbar-left">
                    <div class="form-group">
                        <input type="text" class="form-control" placeholder="请输入内容">
                    </div>
                    <button type="submit" class="btn btn-default">搜索</button>
                </form>
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="goodsCart.html">购物车</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                           aria-expanded="false">联系客服 <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">帮助中心</a></li>
                            <li><a href="#">售后服务</a></li>
                            <li><a href="#">Something else here</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="#">Separated link</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
</div>
<div class="login-wrapper">
    <form method="post" action="login.user">
        <div class="input-group">
            <span class="input-group-addon" id="basic-addon1">账<i>账户</i>户</span>
            <input type="text" class="form-control"  name="uname" id="uname" placeholder="Username" aria-describedby="basic-addon1">
        </div>
        <div class="input-group">
            <span class="input-group-addon" id="basic-addon1">密<i>密码</i>码</span>
            <input type="password" class="form-control" name="upwd" id="upwd" placeholder="Password" aria-describedby="basic-addon1">
        </div>
        <div class="button-wrapper">
            <input class="btn btn-default" type="submit" value="登录"  onclick="return fun();">
            <button class="btn btn-default" type="button">注册</button>
        </div>
    </form>
</div>

<script>
   function fun(){
	   /* alert("dfjdkfj"); */
	   var uname=$("#uname").val().trim();
	   if(uname.length==0){
		   alert("用户名不能为空，请输入用户名");
		   return false;
	   }
	   var upwd=$("#upwd").val().trim();
	   if(upwd.length==0){
		   alert("密码不能为空，请输入密码");
		   return false;
	   }
	   
	   /* 验证用户名是否存在 */
	  var flag=check("checkName.user",{uname:uname},"用户名不存在");
	/*   alert(flag) */
	  if(flag==false){
		  return false;
	  }
	   
	  /* 验证密码是否正确  */
	   flag=check("checkPassword.user",{uname:uname,upwd:upwd},"密码不正确！");
	  
	  if(flag==false){
		  return false;
	  }
	  
	  flag=check("checklevel.user",{uname:uname,upwd:upwd},"没有权限登录！")
	  
	   return flag;
   }
   
   
   function check(url,data,str){
	   var flag=true;
	   $.ajax({
		   url:url,
		   data:data,
		   async:false,
		   dataType:"json",
		   success:function(result){
			   /* alert(result); */
			   if(result.flag==false){
				   alert(str);
				   flag= false;
			   }
		   }
	   })
	   return flag;
   }
</script>
</body>
</html>